const apiURL = 'http://47.94.23.135:8080';

const wxRequest = (params, url) => {
	wx.request({
		url,
		method: params.method || 'GET',
		data: params.data || {},
		header: {
			Accept: 'application/json',
			'Content-Type': 'application/json',
		},
		success(res) {
			if(params.success) {
				params.success(res);
			}
		},
		fail(res) {
			if(params.fail) {
				params.fail(res);
			}
		},
		complete(res) {
			if(params.complete) {
				params.complete(res);
			}
		},
	});
};

const saveUserInfo = (params) => {
  wxRequest({ success: params.success ,fail: params.fail,data:params.data}, apiURL+'/sys/wx/getSessionKey');
};
const getParents = (params) => {
  wxRequest({ success: params.success ,fail: params.fail,data:params.data}, apiURL+'/sys/parents/edit');
};
const getMateList = (params) => {
  wxRequest({ success: params.success ,fail: params.fail,data:params.data}, apiURL+'/sys/meta/list');
};
const getBobyList = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/baby/list');
};
const bobySave = (params) => {
  wxRequest({ success: params.success ,data:params.data,method:"post"}, apiURL+'/sys/baby/save');
};
const bobyRemove = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/baby/remove');
};
const wxlist = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/course/wxlist');
};
const kcDetail = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/course/getDetail');
};
//根据经纬度查询地名列表
const getSiteName = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/address/getName');
};
//根据地名查询经纬度
const getLocationByName = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/address/getNeighbourByName');
};
const orderSave = (params) => {
  wxRequest({ success: params.success ,data:params.data,method:"post"}, apiURL+'/sys/order/save');
};
const orderInfo = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/order/edit');
};

const orderList = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/order/list');
};
const loginByPhone = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/wx/loginByPhone');
};
const getUserPoint = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/userAccount/getUserPoint');
};
const sendSms = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/veriCode/sendSms');
};
const redList = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/redBag/list');
};
const getRedTotal = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/redBag/getTotal');
};
const listByTime = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/order/listByTime');
};
//保存评价
const commentsSave = (params) => {
  wxRequest({ success: params.success ,data:params.data,method:"post"}, apiURL+'/sys/comments/save');
};
//课程推荐
const recommendList = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/course/recommendList');
};
//评价列表
const commentsList = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/comments/list');
};
//查询可用红包数量
const getTotal = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/redBag/getTotal');
};
//微信统一支付接口
const topay = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/wx/topay');
};
//支付成功后保存结果
const paySuccess = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/order/paySuccess');
};
//退款
const drawBack = (params) => {
  wxRequest({ success: params.success ,data:params.data}, apiURL+'/sys/order/drawBack');
};

module.exports = {
  saveUserInfo,
  getMateList,
  getBobyList,
  bobyRemove,
  bobySave,
  wxlist,
  getSiteName,
  getLocationByName,
  kcDetail,
  orderSave,
  orderInfo,
  orderList,
  loginByPhone,
  getUserPoint,
  sendSms,
  redList,
  getRedTotal,
  listByTime,
  commentsSave,
  recommendList,
  commentsList,
  getTotal,
  topay,
  paySuccess,
  drawBack,
  getParents
};